﻿Imports Oracle.DataAccess.Client
Public Class fListaPrecios
    Dim lidLista As String
    Dim daGloDatoslistas As lbGlobalcom.dsGlobalTableAdapters.GLO_DATOSTABLASTableAdapter
    Public ReadOnly Property Lista() As String
        Get
            Return lidLista
        End Get
    End Property
    Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click
        Me.DialogResult = Windows.Forms.DialogResult.Cancel
    End Sub
    Private Function TipoEstado(ByVal Estado As String) As String
        Select Case Estado
            Case "Activas"
                Return "A"
            Case "Inactivas"
                Return "I"
            Case Else
                Return ""
        End Select
    End Function
    Private Sub consultar()
        Dim Conn As OracleConnection = New OracleConnection(My.Settings.ConnectionString)
        Dim cmd As OracleCommand = Conn.CreateCommand
        cmd.CommandText = "SELECT * FROM PRO_ENCALISTAPRECIOS "
        Dim qWhere As String = "WHERE "
        Dim CuentaW As Int16 = 0
        If Me.txtNombreLista.Text.Trim.Length > 0 Then
            CuentaW += 1
            qWhere &= "DESCRIPCION LIKE '%" & Me.txtNombreLista.Text & "%'"
        End If
        If Me.cbEstado.Text <> "Todas" Then
            If CuentaW > 0 Then _
                qWhere &= " AND "
            CuentaW += 1
            qWhere &= "ESTADO =" & Me.cbEstado.SelectedValue
        End If
        If CuentaW = 0 Then _
            qWhere = ""
        cmd.CommandText &= qWhere
        Try
            Conn.Open()
            DsProductos.PRO_ENCALISTAPRECIOS.Rows.Clear()
            DsProductos.PRO_ENCALISTAPRECIOS.Load(cmd.ExecuteReader)
            Conn.Close()
            PRO_ENCALISTAPRECIOSDataGridView.Focus()
        Catch ex As Exception
            MessageBox.Show(ex.Message)
            lbGlobalcom.cError.SalvaError(ex, "Samuel")
        End Try
    End Sub

    Private Sub btnConsulta_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnConsulta.Click
        Try
            consultar()
        Catch ex As Exception
            Throw ex
        End Try
    End Sub

    Private Sub fListaProductos_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Me.cbEstado.Text = "Todas"
        daGloDatoslistas = New lbGlobalcom.dsGlobalTableAdapters.GLO_DATOSTABLASTableAdapter()
        Try
            daGloDatoslistas.FillByIdGrupo(DsGlobal.GLO_DATOSTABLAS, "es")
        Catch ex As Exception
            MessageBox.Show(ex.Message)
            lbGlobalcom.cError.SalvaError(ex, "Samuel")
        End Try
    End Sub
    Private Sub AsignaLista(ByVal Fila As Integer)
        If Fila >= 0 Then
            lidLista = PRO_ENCALISTAPRECIOSDataGridView.Rows(Fila).Cells("IDLISTA").Value
            Me.DialogResult = Windows.Forms.DialogResult.OK
        End If
    End Sub

    Private Sub PRO_ENCALISTAPRECIOSDataGridView_CellMouseDoubleClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellMouseEventArgs) Handles PRO_ENCALISTAPRECIOSDataGridView.CellMouseDoubleClick
        AsignaLista(e.RowIndex)
    End Sub

    Private Sub PRO_ENCALISTAPRECIOSDataGridView_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles PRO_ENCALISTAPRECIOSDataGridView.KeyDown
        If e.KeyData = Keys.Enter Then
            AsignaLista(PRO_ENCALISTAPRECIOSDataGridView.CurrentRow.Index)
        End If
    End Sub

    Private Sub txtNombreLista_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtNombreLista.KeyDown
        Try

            Select Case e.KeyCode
                Case 13
                    consultar()
            End Select
        Catch ex As Exception
            Throw ex
        End Try
    End Sub
End Class